 

module.exports = async function ( ctx) {
  
   ctx.uid = 0;
   var expressSid=decodeURIComponent(ctx.cookies.get('express.sid'));
   var csrf_token= ctx.cookies.get('_csrf') ;
   let authorization = ctx.request.headers.authorization;
   // console.log("request.headers:",authorization, typeof authorization)
   // console.log("ctx.request.body:",ctx.request.body.token,"expressSid:",typeof expressSid ==="string")
   if(  expressSid !="undefined" ){
      let  sid = expressSid.split(".")[0];
      ctx.sid   = ctx.req.sid = sid;
      ctx.req.csrf_token=ctx.csrf_token =csrf_token
   }else if(authorization){
      ctx.sid   = ctx.req.sid = authorization;
      // console.log("ctx.sid:",ctx.sid)
   }

    
   
   // //console.log("ctx:",ctx)
   // //console.log("---auth------");
}